package beanLifeCycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * 
 * @author qiboshi
 * below is bean level interface
 * BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean
 */
public class Car implements BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean {

	private String brand;
	private String color;
	private int maxSpeed;
	
	private BeanFactory beanFactory;
	private String beanName;
	
	
	
	public Car() {
		System.out.println("调用Car()构造函数");
	}

	/**
	 * @return the brand
	 */
	public String getBrand() {
		return brand;
	}

	/**
	 * @param brand the brand to set
	 */
	public void setBrand(String brand) {
		System.out.println("调用setBrand()设置属性");
		this.brand = brand;
	}

	/**
	 * @return the color
	 */
	public String getColor() {
		return color;
	}

	/**
	 * @param color the color to set
	 */
	public void setColor(String color) {
		System.out.println("调用setColor()设置属性");
		this.color = color;
	}

	/**
	 * @return the maxSpeed
	 */
	public int getMaxSpeed() {
		return maxSpeed;
	}

	/**
	 * @param maxSpeed the maxSpeed to set
	 */
	public void setMaxSpeed(int maxSpeed) {
		System.out.println("调用setMaxSpeed()设置属性");
		this.maxSpeed = maxSpeed;
	}

	
	@Override
	public void setBeanName(String beanName) {
		System.out.println("调用BeanNameAware.setBeanName()");
		this.beanName = beanName;
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("调用BeanFactoryAware.setBeanFactory()");
		this.beanFactory = beanFactory;
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("调用InitializingBean.afterPropertiesSet()");
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("调用DisposableBean.destroy()");
	}
	
	
	public void myInit(){
		System.out.println("调用init-method所指定的myInit(),将maxSpeed设置为240");
		this.maxSpeed = 240;
	}
	
	public void myDestory(){
		System.out.println("调用destory-method所指定的myDestory()");
	}

}
